using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Workstations.Queries;

/// <summary>
/// 工位分页查询命令。
/// </summary>
/// <param name="LineId"></param>
public record GetWorkstationListWithPagedQuery(
    long LineId,
    int PageNumber,
    int PageSize) : IPagedQuery, IRequest<IResult<PagedList<MdWorkstationDto>>>;

internal sealed class GetWorkstationListWithPagedQueryHandler(IRepository<MdWorkstation> repo) : IRequestHandler<GetWorkstationListWithPagedQuery, IResult<PagedList<MdWorkstationDto>>>
{
    public async Task<IResult<PagedList<MdWorkstationDto>>> Handle(GetWorkstationListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetPagedListAsync(m => m.LineId == request.LineId, request.PageNumber, request.PageSize, m => m.Order, false, cancellationToken);
        return Result.From(items.Adapt<PagedList<MdWorkstationDto>>());
    }
}
